package com.xihu.socielserver.controller;

import com.xihu.socielserver.service.MyActivityBiz;
import com.xihu.socielserver.entity.MyActivity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin("*")
@Controller
@RequestMapping("/myactivity")
public class MyActivityController {
    @Autowired
    private MyActivityBiz biz;

    @RequestMapping("/insert")
    @ResponseBody
    public Map insert(MyActivity myActivity){
        MyActivity activity = myActivity;
        Map map=new HashMap();
        int flag=biz.insertMyActivity(myActivity);
        System.out.println(flag);
        if(flag==1){
            map.put("isOk", true);
            map.put("msg", "添加成功");
        }else {
            map.put("isOk",false);
            map.put("msg", "添加失败");
        }
        return map;
    }

    @RequestMapping("/show")
    @ResponseBody
    public Map show(int userId){
        List<MyActivity> list = biz.showMyActivity(userId);
        Map map=new HashMap();
        if(list != null){
            map.put("isOk",true);
            map.put("myactivity",list);
            map.put("msg","展示成功");
        }else{
            map.put("isOk",false);
            map.put("myactivity", list);
            map.put("msg", "目前没有活动！");
        }
        return map;
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map selectActivity(MyActivity activity){
        List<MyActivity> list = biz.selectMyActivity(activity);
        Map map=new HashMap();
        if(list != null){
            map.put("isOk",true);
            map.put("list",list);
            map.put("msg","展示成功");
        }else{
            map.put("isOk",false);
            map.put("list", list);
            map.put("msg", "目前没有活动！");
        }
        return map;
    }

    @RequestMapping("/updateState")
    @ResponseBody
    public Map updateState(MyActivity activity){
        System.out.println(activity);
        int flag = biz.updateMyActivity(activity);
        System.out.println(flag);
        Map map=new HashMap();
        if(flag==1){
            map.put("isOk",true);
            map.put("msg","参与完成");
        }
        return map;
    }
}
